//
//  SetUPViewController.m
//  EducationAdminClient
//
//  Created by KWSD on 15/12/31.
//  Copyright © 2015年 周佳兴. All rights reserved.
//

#import "SetUPViewController.h"
#import "FeedbackViewController.h"
@interface SetUPViewController ()<UIAlertViewDelegate>

@end

@implementation SetUPViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.tabbarView.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *feedbackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [feedbackBtn setTitleColor:[UIColor colorWithRed:0x5b/256.0f green:0x5b/256.0f blue:0x5b/256.0f alpha:1] forState:UIControlStateNormal];
    feedbackBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    feedbackBtn.layer.masksToBounds = YES;
    feedbackBtn.layer.cornerRadius = 10.0;
    feedbackBtn.layer.borderColor = [UIColor colorWithRed:0xc1/256.0f green:0xc1/256.0f blue:0xc1/256.0f alpha:1].CGColor;
    feedbackBtn.layer.borderWidth = 1.0f;
    feedbackBtn.frame = CGRectMake(20, 68/2, ([UIScreen mainScreen].bounds.size.width-40), 42);
    [feedbackBtn setTitle:@"系统反馈" forState:UIControlStateNormal];
    
    [feedbackBtn setBackgroundColor:[UIColor whiteColor]];
    
    [feedbackBtn addTarget:self action:@selector(feedbackBtn:) forControlEvents:UIControlEventTouchUpInside];
    feedbackBtn.layer.cornerRadius = 8;
    [self.view addSubview:feedbackBtn];
    
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor whiteColor];
    UIButton *btn =[UIButton  buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(20, feedbackBtn.frame.origin.y+42+34/2, feedbackBtn.frame.size.width, 42);
    [self.view addSubview:btn];
    btn.backgroundColor = [UIColor colorWithRed:0xff/256.0f green:0x5e/256.0f blue:0x5e/256.0f alpha:1];
    btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [btn setTitle:@"退出登录" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    btn.layer.cornerRadius = 8;
    
    
    
    
    UIButton *btn1 =[UIButton  buttonWithType:UIButtonTypeSystem];
    btn1.frame = CGRectMake(20, feedbackBtn.frame.origin.y+42+42+42+34/2, feedbackBtn.frame.size.width, 42);
    [self.view addSubview:btn1];
    btn1.backgroundColor = [UIColor colorWithRed:0xff/256.0f green:0x5e/256.0f blue:0x5e/256.0f alpha:1];
    btn1.titleLabel.font = [UIFont systemFontOfSize:16];
    [btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [btn1 setTitle:@"清除缓存" forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(clean:) forControlEvents:UIControlEventTouchUpInside];
    btn1.layer.cornerRadius = 8;

    
    
    
    [self createLeftNavBar];
}


-(void)clean:(UIButton *)btn{
    
    
    if(CURRENTVERSION <9.0){
        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:nil message:@"是否确认删除" delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"确定", nil];
        alert.delegate = self;
        [alert show];
    }else{
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"是否确认删除" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *cancelAction1 = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"delete");
            
            [self removeCashes];
            
            
        }];
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alertController addAction:cancelAction];
        [alertController addAction:cancelAction1];
        [self presentViewController:alertController animated:YES completion:^{
            
        }];
        
    }

    
    
}

-(void)removeCashes{
    BOOL removeCashes = removeCaches(userName());
    
    NSString *messageStr = @"";
    if (removeCashes) {
        messageStr = @"成功";
    }else{
        messageStr = @"失败";
    }
    
    if(CURRENTVERSION <9.0){
        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:nil message:messageStr delegate:self cancelButtonTitle:@"否" otherButtonTitles:nil, nil];
        alert.delegate = self;
        [alert show];
    }else{
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:messageStr preferredStyle:UIAlertControllerStyleAlert];
        
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alertController addAction:cancelAction];
        [self presentViewController:alertController animated:YES completion:^{
            
        }];
        
    }

}
-(void)btnClick:(UIButton *)btn{
    NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
    saveLoginState(NLOGSTATE);
//#ifdef Main
    
    //#ifdef Main
    if([getUIStyle() isEqualToString:STYLE0]){
        NSLog(@"主项目程序");
        [noti postNotificationName:@"login" object:@"exit"];
    }else{
//#elif Student
        NSLog(@"学员端程序");
        [noti postNotificationName:@"login" object:@"exit"];
    }
//#elif Teacher
//    NSLog(@"老师端程序");
//#else
//    NSLog(@"都不是");
//#endif
    
}


- (void)feedbackBtn:(UIButton *)sender{
    NSLog(@"lakjsdf");
    FeedbackViewController *fbvc = [[FeedbackViewController alloc] init];
    [self.navigationController pushViewController:fbvc animated:YES];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - UIAlertDelegate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        
    }else{
        [self removeCashes];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
